<?php
require_once LOGIC_ROOT . 'BaseUser.php';
/**
 * UserIdentity represents the data needed to identity a user.
 * It contains the authentication method that checks if the provided
 * data can identity the user.
 */
class UserIdentity extends CUserIdentity
{
	private $_id;

	/**
	 * Authenticates a user.
	 * @return boolean whether authentication succeeds.
	 */
	public function authenticate()
	{
		$userLogic = BaseUser::getInstance();
		$res = $userLogic->checkPwd($this->username, $this->password);
		if (ErrorDef::OK == $res['err'])
		{
			$user = $res['data'];
			$this->_id = $user->uid;
			$this->errorCode = ErrorDef::OK;
		}else
		{
			$this->errorCode = $res['err'];
		}
		return $this->errorCode==ErrorDef::OK;
	}

	/**
	 * @return integer the ID of the user record
	 */
	public function getId()
	{
		return $this->_id;
	}
}
